package edu.hawaii.halealohacli;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * A JUnit test for testing Main for correctness.
 * 
 * @author Chris Fang
 */
public class TestMain {

  Main testMain;
  String error;
  
  /**
   * Create an instance of Main to test.
   */
  public TestMain() {
    testMain = new Main();
  }

  /**
   * Test createClient method for correct output.
   */
  @Test
  public void testCreateClient() {
    // If the connection was made, the message should start with this
    error = "testCreateClient failed: Expected a message to be returned";
    assertTrue(error, testMain.setUpClient().contains("Connected"));
  }

  /**
   * Test getClient method to see if a healthy client is returned.
   */
  @Test
  public void testGetClient() {
    testMain.setUpClient();
    error = "testGetClient failed: Expected true";
    assertTrue(error, testMain.getClient().isHealthy());
  }

  /**
   * Test isConnected method for correctness.
   */
  @Test
  public void testIsConnected() {
    testMain.setUpClient();
    error = "testIsConnected failed: Expected true";
    assertTrue(error, testMain.isConnected());
    // If is connected is reporting true, the client should be healthy
    error = "testIsConnected failed: Expected true";
    assertTrue(error, testMain.getClient().isHealthy());
  }

  /**
   * Test setConnected method for correctness.
   */
  @Test
  public void testSetConnected() {
    testMain.setConnected(true);
    error = "testSetConnected failed: Expected true";
    assertTrue(error, testMain.isConnected());
    testMain.setConnected(false);
    error = "testSetConnected failed: Expected false";
    assertFalse(error, testMain.isConnected());
  }
}
